﻿using QRCoder;
using System.Drawing.Imaging;
using System.IO;
using System.Security.Policy;
using System.Web;

namespace Batman.Cms.Core.Utils
{
    /// <summary>
    /// 二维码工具类
    /// </summary>
    public class QrCodeUtil
    {
        /// <summary>
        /// 生成url跳转二维码
        /// 扫码二维码后进行页面跳转
        /// </summary>
        public static byte[] GenerateUrlQrCode(string url)
        {
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new QRCode(qrCodeData);
            var qrCodeAsBitmap = qrCode.GetGraphic(20);

            using (var mm = new MemoryStream())
            {
                qrCodeAsBitmap.Save(mm, ImageFormat.Png);
                return mm.ToArray();
            }
        }
    }
}
